package com.yaocw.baseproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yaocw.baseproject.R;
import com.yaocw.baseproject.entity.HomeMenuEntity;

import java.util.List;

public class HomeMenusAdapter extends RecyclerView.Adapter {
    private final Context mContext;
    private List<HomeMenuEntity> mDatas;

    public HomeMenusAdapter(Context mContext, List<HomeMenuEntity> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.home_menu, parent, false);
        return new HomeMenuViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        HomeMenuViewHolder vh = (HomeMenuViewHolder) holder;
        vh.tvTitle.setText(mDatas.get(position).getTitle());
        vh.ivMenu.setImageResource(mDatas.get(position).getImageUrl());
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public class HomeMenuViewHolder extends RecyclerView.ViewHolder {
        private TextView tvTitle;
        private ImageView ivMenu;

        public HomeMenuViewHolder(@NonNull View itemView) {
            super(itemView);

            tvTitle = itemView.findViewById(R.id.tv_title);
            ivMenu = itemView.findViewById(R.id.iv_menu);
        }
    }
}
